package com.zhixiang.xaec.service.system.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zhixiang.core.dao.BaseDao;
import com.zhixiang.core.service.impl.BaseServiceImpl;
import com.zhixiang.xaec.dao.system.PositionDao;
import com.zhixiang.xaec.entity.system.Position;
import com.zhixiang.xaec.service.system.PositionService;
@Service
public class PositionServiceImpl extends BaseServiceImpl<Position, Long>
implements PositionService
{

    @Override
    @Resource(type=PositionDao.class)
    public void setBaseDao(BaseDao<Position, Long> dao)
    {
        setDao(dao);       
    }
    
    @Override
    public Position save(Position position){
        getDao().save(position);
        List<Position>list= getDao().findByHql("FROM Position p WHERE p.parentId=?", new Object[]{position.getId()});
        for(Position p:list){
            p.setState(position.getState());
            getDao().save(p);
        }
        return position;
    }
    @Override
    public String delete(String[] ids)
    {  
        for(String id:ids){
            getDao().remove(Long.valueOf(Long.valueOf(id)));
        }      
        return null;
    }

    @Override
    public List<Position> findByParentId(Long parentId)
    {
        if(!"".equals(parentId)&&parentId!=null){
            return getDao().findByHql("FROM Position p WHERE p.parentId=?", new Object[]{parentId});
        }
        return null;
    }

}
